class Elink < ActiveRecord::Base
  belongs_to :tema

  def before_save
    self.elink_size = Integer(self.elink.split("|")[3])
    self.elink_hash = self.elink.split("|")[4]
  end

  def nombre
    read_attribute('elink').split("|")[2]
  end

  def size
    read_attribute('elink_size')
  end

  def hash
    read_attribute('elink_hash')
  end

  def self.total_elinks_size
    Elink.find(:all).inject(0) { |sum, elink| sum + elink.elink_size }
  end
end
